<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
      <a-button type="primary" icon="audit" @click="downLoadExcel()">下载模板</a-button>
      <a-button type="primary" icon="download" v-has="'llbbdepositll:download'" @click="ExportData()" >导出</a-button>
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <a-button type="primary" icon="import" v-has="'llbbdepositll:import'" @click="ImportData" >导入</a-button>
      <a-button type="primary" icon="reload" @click="RefreshData">刷新数据</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="display: none">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleViewReport(record)">查看</a>&nbsp;&nbsp;
          <a @click="handleExportXls(record)">导出</a>&nbsp;&nbsp;
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDel(record)">
            <a>删除</a>
          </a-popconfirm>
<!--          <a-divider type="vertical" />-->
<!--          <a-dropdown>-->
<!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item>-->
<!--                <a @click="handleDetail(record)">详情</a>-->
<!--              </a-menu-item>-->
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a>删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
<!--            </a-menu>-->
<!--          </a-dropdown>-->
        </span>

      </a-table>
    </div>

    <llbb-deposit-ll-modal ref="modalForm" @ok="modalFormOk"></llbb-deposit-ll-modal>
    <SjrqRefressModal ref="refressModel" @ok="modalFormOk"></SjrqRefressModal>
    <ImportModel ref="importModel" @ok="modalFormOk"></ImportModel>
    <ExportModel ref="exportModel" @ok="modalFormOk"></ExportModel>
    <ViewModel ref="viewModel" @ok="modalFormOk"></ViewModel>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LlbbDepositLlModal from './modules/LlbbDepositLlModal'
  import { deleteAction, downFile } from '@/api/manage'
  import SjrqRefressModal from './SjrqRefressModal'
  import ImportModel from './ImportModel'
  import ExportModel from './ExportModel'
  import ViewModel from './modules/ViewModel'
  import {ACCESS_TOKEN} from '@/store/mutation-types'
  import Vue from 'vue'
  export default {
    name: 'LlbbDepositLlList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ImportModel,
      LlbbDepositLlModal,
      SjrqRefressModal,
      ExportModel,
      ViewModel
    },
    data () {
      return {
        description: 'llbb_deposit_ll管理页面',
        // 表头
        columns: [
          {
            title:'报表名称',
            align:"center",
            dataIndex: '',
            customRender:function (t,r,index) {
              return '阜新银行存款利率自律统计月报';
            }
          },
          {
            title:'数据日期',
            align:"center",
            dataIndex: 'sjrq'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/reportInfo/llbbDepositLl/list",
          delete: "/reportInfo/llbbDepositLl/delete",
          deleteBatch: "/reportInfo/llbbDepositLl/deleteBatch",
          exportXlsUrl: "/reportInfo/llbbDepositLl/exportXls",
          importExcelUrl: "reportInfo/llbbDepositLl/importExcel",
          downLoadExcel: "reportInfo/llbbDepositLl/downLoadExcel",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      downLoadExcel() {
        let fileName = "阜新银行存款利率自律统计月报";
        let param = "";
        downFile(this.url.downLoadExcel,param).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xlsx')
          }else{
            let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName+'.xlsx')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        })
      },
      RefreshData(){
        this.$refs.refressModel.showModal();
      },
      ImportData(){
        this.$refs.importModel.showModal();
      },
      ExportData(){
        this.$refs.exportModel.showModal();
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'bz',text:'币种'})
        fieldList.push({type:'number',value:'qntqye',text:'去年同期余额'})
        fieldList.push({type:'number',value:'syfs',text:'上月发生额'})
        fieldList.push({type:'number',value:'qntqfs',text:'去年同期发生'})
        fieldList.push({type:'number',value:'syll',text:'上月加权平均利率'})
        fieldList.push({type:'number',value:'syye',text:'上月余额'})
        fieldList.push({type:'number',value:'qntqll',text:'去年同期加权平均利率'})
        fieldList.push({type:'string',value:'cplx',text:'产品类型'})
        fieldList.push({type:'string',value:'ckqxlx',text:'产品期限类型'})
        fieldList.push({type:'string',value:'cklx',text:'存款类型'})
        fieldList.push({type:'number',value:'dyye',text:'当月余额'})
        fieldList.push({type:'number',value:'yetb',text:'余额同比'})
        fieldList.push({type:'number',value:'yehb',text:'余额环比'})
        fieldList.push({type:'number',value:'dyfs',text:'当月发生额'})
        fieldList.push({type:'number',value:'fstb',text:'发生额同比'})
        fieldList.push({type:'number',value:'fshb',text:'发生额环比'})
        fieldList.push({type:'number',value:'dyjqpjll',text:'当月加权平均利率'})
        fieldList.push({type:'number',value:'tb',text:'同比'})
        fieldList.push({type:'number',value:'hb',text:'环比'})
        fieldList.push({type:'number',value:'dyzgll',text:'当月最高利率（%）'})
        fieldList.push({type:'date',value:'sjrq',text:'数据日期'})
        this.superFieldList = fieldList
      },
      handleDel(record){
        var that = this;
        deleteAction(that.url.delete, {sjrq: record.sjrq}).then((res) => {
          if (res.success) {
            //重新计算分页问题
            that.reCalculatePage(1)
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
      handleViewReport(record){
        var token=Vue.ls.get(ACCESS_TOKEN);
        var vurl=window._CONFIG['domianURL']+"/jmreport/view/621136978490908672?";
        vurl+="token="+token+"&sjrq="+record['sjrq'];
        window.open(vurl)
        // this.$refs.viewModel.showModal(record['sjrq']);
      },
      handleExportXls(record){
        let fileName = "阜新银行存款利率自律统计月报";
        let param = new Object();
        var date=record['sjrq'];
        param['sjrq']=date;//.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
        downFile(this.url.exportXlsUrl,param).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xlsx')
          }else{
            let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName+'.xlsx')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        });
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>